import { getToken, setToken, removeToken } from "@/request/token"
import { getmenu, setmenu, removemenu } from "@/request/menu"
import { loginApi } from "@/api/login"
export default {
    namespaced: true,
    state: {
        token: getToken(),
        menuList:getmenu()
    },
    mutations: {
        setToken(state, token) {
            state.token = token
            setToken(token)
        },
        removeToken(state) {
            state.token = null
            removeToken()
        },
        setmenu(state, menu) {
            state.menuList = menu
            setmenu(menu)
        },
        removemenu(state) {
            state.menuList = []
            removemenu()
        }
    },
    actions: {
        async loginActions({ commit }, userinfo) {
            let res = await loginApi(userinfo)
            commit('setToken', res.token)
            commit('setmenu',res)
        }
    }
}